<?php

namespace frontend\controllers;

use common\models\CenterInProject;
use common\models\DbVersion;
use common\models\DynamicCode;
use common\models\export\SubjectSubjWord;
use common\models\export\SubjectVisitPlan;
use common\models\Helper;
use common\models\operatelogs\Logs;
use common\models\SubjectActionLog;
use common\models\SubjectVisitDate;
use common\models\TabCheck;
use common\models\Logger;
use common\models\Subject;
use common\models\RepeatSubject;
use common\models\SubjectSearch;
use frontend\modules\approve\models\ApvProject;
use frontend\modules\reward\models\RewRule;
use Yii;
use yii\filters\VerbFilter;
use yii\helpers\Json;
use yii\web\Controller;
use yii\web\NotFoundHttpException;

/**
 * SubjectController implements the CRUD actions for Subject model.
 *
 * @author Bran <lin.yang@ht-med.com>
 * @copyright (c) 2015, HT-MED
 * @package common.models
 * @since version 1.0
 */
class SubjectController extends Controller
{

    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['post'],
                ],
            ],
        ];
    }
    
    /**
     * 受试者概况
     */
    public function actionTwoView($id = 1, $tag = 0, $tags = 0)
    {
        $model = Subject::findOne(['seq' => $id]);
        $tabCheck = new TabCheck;
        $checks = $tabCheck->getChecksBySeq($id);
        return $this->render('two-view', [
            'model' => $model,
            'checks' => $checks,
            'tabCheck' => $tabCheck,
            'tag' => $tag,
            'tags' => $tags,
        ]);
    }
    
    protected function findModel($id)
    {
        $model = Subject::findOne(intval($id));
        if ($model !== null && $model->project_id == getSession('defaultPid')) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
 
}
